package com.ruoyi.zhjj.service.impl;

import java.util.List;

import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.enums.DelStatus;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.zhjj.domain.ZhjjContractorInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.zhjj.mapper.ZhjjQualificationMapper;
import com.ruoyi.zhjj.domain.ZhjjQualification;
import com.ruoyi.zhjj.service.IZhjjQualificationService;

/**
 * 证书信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-29
 */
@Service
public class ZhjjQualificationServiceImpl implements IZhjjQualificationService
{
    @Autowired
    private ZhjjQualificationMapper zhjjQualificationMapper;

    /**
     * 查询证书信息
     *
     * @param id 证书信息主键
     * @return 证书信息
     */
    @Override
    public ZhjjQualification selectZhjjQualificationById(Long id)
    {
        return zhjjQualificationMapper.selectZhjjQualificationById(id);
    }

    @Override
    public ZhjjQualification selectZhjjQualificationByExtSysId(Integer extSysId) {
        return zhjjQualificationMapper.selectZhjjQualificationByExtSysId(extSysId);
    }

    /**
     * 查询证书信息列表
     *
     * @param zhjjQualification 证书信息
     * @return 证书信息
     */
    @Override
    public List<ZhjjQualification> selectZhjjQualificationList(ZhjjQualification zhjjQualification)
    {
        return zhjjQualificationMapper.selectZhjjQualificationList(zhjjQualification);
    }

    /**
     * 新增证书信息
     *
     * @param zhjjQualification 证书信息
     * @return 结果
     */
    @Override
    public int insertZhjjQualification(ZhjjQualification zhjjQualification)
    {
        zhjjQualification.setCreateTime(DateUtils.getNowDate());
        zhjjQualification.setCreateBy(SecurityUtils.getUsername());
        zhjjQualification.setDelFlag(DelStatus.EXITS.getCode());
        // 重复数据验证
        try{
            ZhjjQualification existingInfo = selectZhjjQualificationByExtSysId(zhjjQualification.getExtSysId());
            if (existingInfo != null) {
                throw new ServiceException("源数据表ID已存在：", HttpStatus.DATA_EXIST);
            }

            return zhjjQualificationMapper.insertZhjjQualification(zhjjQualification);

            //        TODO 将新增消息传入到RabbitMQ
        }catch (Exception e){
            throw new ServiceException("操作失败：" + e.getMessage(), HttpStatus.ERROR);
        }

    }

    /**
     * 修改证书信息
     *
     * @param zhjjQualification 证书信息
     * @return 结果
     */
    @Override
    public int updateZhjjQualification(ZhjjQualification zhjjQualification)
    {
        zhjjQualification.setUpdateTime(DateUtils.getNowDate());
        zhjjQualification.setUpdateBy(SecurityUtils.getUsername());
        return zhjjQualificationMapper.updateZhjjQualification(zhjjQualification);
    }

    /**
     * 批量删除证书信息
     *
     * @param ids 需要删除的证书信息主键
     * @return 结果
     */
    @Override
    public int deleteZhjjQualificationByIds(Long[] ids)
    {
        return zhjjQualificationMapper.deleteZhjjQualificationByIds(ids);
    }

    /**
     * 删除证书信息信息
     *
     * @param id 证书信息主键
     * @return 结果
     */
    @Override
    public int deleteZhjjQualificationById(Long id)
    {
        return zhjjQualificationMapper.deleteZhjjQualificationById(id);
    }
}
